

using System.Linq;
using Abp.Authorization;
using Abp.Configuration.Startup;
using Abp.Localization;
using Abp.MultiTenancy;
using LTMCompanyName.YoyoCmsTemplate.Authorization;

// ReSharper disable once CheckNamespace
namespace LTMCompanyName.YoyoCmsTemplate.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="CollegePermissions" /> for all permission names. College
    ///</summary>
    public class CollegeAuthorizationProvider : AuthorizationProvider
    {
        private readonly bool _isMultiTenancyEnabled;

        public CollegeAuthorizationProvider()
        {

        }


        public CollegeAuthorizationProvider(bool isMultiTenancyEnabled)
        {
            _isMultiTenancyEnabled = isMultiTenancyEnabled;
        }

        public CollegeAuthorizationProvider(IMultiTenancyConfig multiTenancyConfig)
        {
            _isMultiTenancyEnabled = multiTenancyConfig.IsEnabled;
        }

        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            // 在这里配置了College 的权限。
            var pages = context.GetPermissionOrNull(AppLtmPermissions.Pages) ?? context.CreatePermission(AppLtmPermissions.Pages, L("Pages"));

            var administration = pages.Children.FirstOrDefault(p => p.Name == AppLtmPermissions.Pages_Exam) ?? pages.CreateChildPermission(AppLtmPermissions.Pages_Exam, L("Pages_Exam"));

            var college = administration.CreateChildPermission(CollegePermissions.College_Node, L("College"));
            college.CreateChildPermission(CollegePermissions.College_Query, L("QueryCollege"));
            college.CreateChildPermission(CollegePermissions.College_Create, L("CreateCollege"));
            college.CreateChildPermission(CollegePermissions.College_Edit, L("EditCollege"));
            college.CreateChildPermission(CollegePermissions.College_Delete, L("DeleteCollege"));
            college.CreateChildPermission(CollegePermissions.College_BatchDelete, L("BatchDeleteCollege"));
            college.CreateChildPermission(CollegePermissions.College_ExportExcel, L("ExportToExcel"));


            //// custom codes



            //// custom codes end
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, AppConsts.LocalizationSourceName);
        }
    }
}
